1

Create a numeric vector with at 6 numbers.
To create a vector you would need the c() function.
cool_numeric_vector <-
  c(4, 8, 15, 16, 23, 42)

cool_numeric_vector
## [1]  4  8 15 16 23 42

2

Now, create a character vector with four distinct strings.
Strings or characters have to be enclosed by quotation marks ("" or '').
cool_character_vector <-
  c("I", "like", "bananas", "and", "rhubarb", "pie")

cool_character_vector
## [1] "I"       "like"    "bananas" "and"     "rhubarb" "pie"

3

Let’s turn to more complex data structures. Create a matrix with two columns using the matrix() function based on the numeric vector you built in the first exercise.
You have to either define the nrow or ncol option to get the proper layout of the matrix.
cool_matrix <-
  matrix(cool_numeric_vector, nrow = 3)

cool_matrix
##      [,1] [,2]
## [1,]    4   16
## [2,]    8   23
## [3,]   15   42

4

Create a list from all the above defined data types.
Just wrap all elements in the list() function
cool_list <-
  list(
    cool_numeric_vector,
    cool_character_vector,
    cool_matrix
  )

cool_list
## [[1]]
## [1]  4  8 15 16 23 42
## 
## [[2]]
## [1] "I"       "like"    "bananas" "and"     "rhubarb" "pie"    
## 
## [[3]]
##      [,1] [,2]
## [1,]    4   16
## [2,]    8   23
## [3,]   15   42

5

Extract the matrix from the list and convert it to a data frame using the as.data.frame() function .
List elements are accessed with [[]].
cool_data_frame <- 
  as.data.frame(cool_list[[3]])

6

Add some column names (e.g., “first” and “second”) for the two columns of the data frame.
You would need the names() function.
names(cool_data_frame) <- c("one", "two")

cool_data_frame
##   one two
## 1   4  16
## 2   8  23
## 3  15  42